<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" slot="detail">
        <a-row :gutter="30">
          <a-col :span="12" :hidden="true">
            <a-form-model-item label="流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle">
              <a-input :max-length="255" :disabled="formDisabled" v-model="model.bpmBizTitle"
                       placeholder="请输入流程名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-show="formDisabled">
            <a-form-model-item label="档案编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ptzhbm">
              <a-input :disabled=true v-model="model.ptzhbm" placeholder="请输入档案编号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="平台名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ptmc">
              <a-input :disabled="formDisabled" v-model="model.ptmc" placeholder="请输入平台名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="会员单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hydw">
              <a-input :disabled="formDisabled" v-model="model.hydw" placeholder="请输入会员单位"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="网址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wz">
              <a-input :disabled="formDisabled" v-model="model.wz" placeholder="请输入网址"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="保管人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bgr">
              <!--            <select-user-by-dep-->
              <!--                :disabled=formDisabled-->
              <!--                v-model="model.bgr"/>-->
              <select-user-by-dep :disabled=formDisabled :multi="false" v-model="model.bgr"/>
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="登录名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dlm">
              <a-input :disabled="formDisabled" v-model="model.dlm" placeholder="请输入登录名"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mm">
              <a-input :disabled="formDisabled" v-model="model.mm" placeholder="请输入密码"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="会员等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hydj">
              <a-input :disabled="formDisabled" v-model="model.hydj" placeholder="请输入会员等级"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="会员有效期始" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hyyxqs">
              <j-date :disabled="formDisabled" placeholder="请选择会员有效期始" v-model="model.hyyxqs" style="width: 48%"/>
              <span class="fontDiy">至</span>
              <j-date :disabled="formDisabled" placeholder="请选择会员有效期止" v-model="model.hyyxqe" style="width: 48%"/>

            </a-form-model-item>
          </a-col>


          <a-col :span="12">
            <a-form-model-item label="ca锁密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="casmm">
              <a-input :disabled="formDisabled" v-model="model.casmm" placeholder="请输入ca锁密码"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="ca锁个数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="casgs">
              <a-input-number
                :disabled="formDisabled"
                :max="99999999"
                :min="0"
                v-model="model.casgs"
                placeholder="请输入ca锁个数"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>


          <a-col :span="24">
            <a-form-model-item label="ca锁有效期始" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="casyxqs">
              <j-date :disabled="formDisabled" placeholder="请选择ca锁有效期始" v-model="model.casyxqs" style="width: 48%"/>
              <span class="fontDiy">至</span>
              <j-date :disabled="formDisabled" placeholder="请选择ca锁有效期止" v-model="model.casyxqe" style="width: 48%"/>
            </a-form-model-item>
          </a-col>
          <!--<a-col :span="12">
            <a-form-model-item label="ca锁有效期止" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="casyxqe">
              <j-date :disabled="formDisabled" placeholder="请选择ca锁有效期止" v-model="model.casyxqe" style="width: 100%" />
            </a-form-model-item>
          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bz">
              <a-textarea :disabled="formDisabled" v-model="model.bz" rows="4" placeholder="请输入备注"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="平台注册授权联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platformContacts">
              <a-input :maxLength="200" :disabled="formDisabled" v-model="model.platformContacts"
                       placeholder="请输入平台注册授权联系人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platformContactsTel">
              <a-input :maxLength="200" :disabled="formDisabled" v-model="model.platformContactsTel"
                       placeholder="请输入联系方式"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-show="formDisabled">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
              <!--            <select-user-by-dep-->
              <!--                :disabled=true-->
              <!--                v-model="model.proposer"/>-->
              <select-user-by-dep :disabled=formDisabled :multi="false" v-model="model.proposer"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-show="formDisabled">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerDeptId">
              <!--<a-input :disabled=formDisabled v-model="model.jbbm" placeholder="请输入经办部门"  ></a-input>-->
              <j-select-depart :disabled=true v-model="model.proposerDeptId"/>
            </a-form-model-item>
          </a-col>

          <a-col :span="24" v-show="formDisabled">
            <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date :disabled=true placeholder="请选择申请时间" v-model="model.createTime" style="width: 48%"/>

            </a-form-model-item>
          </a-col>

        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction } from '@/api/manage'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'

export default {
  name: 'ErpOmcPlatformAccountFinalForm',
  components: {
    SelectUserByDep
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 },
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/add',
        edit: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/edit',
        queryById: '/api/erp/omc/platformaccount/erpOmcPlatformAccountFinal/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      // this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>
